﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using PostSharp.Laos;
using log4net;

namespace ConsolePostSharp
{
    [Serializable]
    [AttributeUsage(AttributeTargets.All, Inherited = true, AllowMultiple = false)]
    public  class LoggerAttribute : OnMethodInvocationAspect
    {
        private static readonly ILog _log = LogManager.GetLogger(typeof(LoggerAttribute));

        /// <summary>
        /// 调用某个方法时执行
        /// </summary>
        /// <param name="eventArgs"></param>
        public override void OnInvocation(MethodInvocationEventArgs eventArgs)
        {
            DateTime time = DateTime.Now;
            string log = "时间：{0}，操作人员 {1}，操作{2}";
            object[] arg = eventArgs.GetArgumentArray();
            log = string.Format(log, time, User.UserID, "删除ID为" + arg[0].ToString() + "的订单！");
            _log.Info(log);
        }
    }
}
